package priv.books.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import priv.books.pojo.Admin;
import priv.books.pojo.ResultMessage;
import priv.books.pojo.User;
import priv.books.service.AdminService;
import priv.books.service.UserService;

/**
 * @author Kris He
 * @date 2022/04/29 11:50
 **/
@RestController
@RequestMapping("/admin")
public class UserController {

    @Autowired
    UserService userService;

    @DeleteMapping("/deleteUserInfo")
    public ResultMessage deleteInfo(Integer id, String ids) {
        try {
            // 调用service 修改方法
            boolean result = false;
            if(id != null && id != 0) {
                // 删除用户详情
                result=userService.remove(new QueryWrapper<User>().eq("id", id));
            } else if(!StrUtil.isBlankOrUndefined(ids)) {
                // 删除用户详情
                result=userService.remove(new QueryWrapper<User>().in("id", StrUtil.split(ids, ',', true, true)));
            }
            if(result) {
                return new ResultMessage(0, "操作成功！");
            }
            return new ResultMessage(207, "操作无响应！");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultMessage(500, "出现异常：" + e.getMessage());
        }
    }
}
